package jsch_demo;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;

import java.util.Properties;

/**
 * Author: hu
 * Date: 2023/5/18 15:43
 */
public class Shell{
private static final String USER="root";
    private static final String PASSWORD="root$123";
    private static final String HOST="192.168.2.253";
    private static final int DEFAULT_SSH_PORT=22;
    public static void main(String[] arg){
        try{
            JSch jsch=new JSch();
            Session session = jsch.getSession(USER,HOST,DEFAULT_SSH_PORT);
            session.setPassword(PASSWORD);
            session.setConfig("kex", "diffie-hellman-group1-sha1");
            session.setConfig("server_host_key", "ssh-rsa,ssh-dss");
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect(30000);   // making a connection with timeout.
            Channel channel=session.openChannel("shell");
            channel.setInputStream(System.in);
            channel.setOutputStream(System.out);
            channel.connect(3*1000);
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
}
